/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.managedbean;

import commonInfrastructure.accountManagement.session.EmployeeSessionBean;
import crm.clientManagement.entity.CompanyEntity;
import frm.billingAndPaymentProcessing.entity.InvoiceEntity;
import frm.billingAndPaymentProcessing.entity.ReceiptEntity;
import frm.billingAndPaymentProcessing.session.ReceiptSessionBean;
import java.io.IOException;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;


/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class ManageReceiptManagedBean {
private ReceiptEntity receipt;
private InvoiceEntity invoice;
private CompanyEntity company;
private String employeeName;

@EJB
ReceiptSessionBean receiptSessionBean;
   @EJB
    EmployeeSessionBean employeeSessionBean;
    /** Creates a new instance of ManageReceiptManagedBean */
    public ManageReceiptManagedBean() {
    }
    public void initView(PhaseEvent event){
        if(receipt==null){
        receipt = (ReceiptEntity)FacesContext.getCurrentInstance().getExternalContext().getFlash().get("receipt"); 
        }
        invoice = receipt.getInvoice();
        company = invoice.getDeliveryOrder().getParentSalesOrder().getCustomer();
        employeeName = employeeSessionBean.getEmployeeById(invoice.getCreatedBy()).getName();
    }
    public void viewAll() throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().redirect("viewAllReceipt.xhtml");
    }
    public ReceiptEntity getReceipt() {
        return receipt;
    }

    public void setReceipt(ReceiptEntity receipt) {
        this.receipt = receipt;
    }

    public InvoiceEntity getInvoice() {
        return invoice;
    }

    public void setInvoice(InvoiceEntity invoice) {
        this.invoice = invoice;
    }

    public CompanyEntity getCompany() {
        return company;
    }

    public void setCompany(CompanyEntity company) {
        this.company = company;
    }

    public String getEmployeeName() {
        return employeeName;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }
}
